package com.joejag.mavenstats.client.utils;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;
import com.joejag.mavenstats.client.service.ChartGenerator;
import com.joejag.mavenstats.client.service.ChartGeneratorAsync;

public class ChartImage extends Image
{
  public ChartImage(String teamname)
  {
    super();

    ChartGeneratorAsync generatorAsync = ChartGenerator.App.getInstance();
    AsyncCallback callback = new AsyncCallback()
    {
      public void onSuccess(Object s)
      {
        String chartName = (String) s;
        String imageUrl = "./displayChart?filename=" + chartName;
        setUrl(imageUrl);
      }

      public void onFailure(Throwable ex)
      {
        Window.alert("Problem loading image: " + ex.getMessage());
      }
    };
    generatorAsync.generateReport(teamname, callback);
  }

}